<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>机构名称</td>
                    <td><input type="text" v-model="querinfo.organName"></td>
                </tr>
                <tr>
                    <td>机构封面</td>
                    <td><input type="file" @change="imgs">
                    <img :src="querinfo.photo" alt="" width="50px" height="50px" v-if="querinfo.photo!=''">
                    </td>
                </tr>
                <tr>
                    <td>特色服务</td>
                    <td><select v-model="querinfo.sever">
                        <option value="">请选择</option>
                        <option value="特殊护理">特殊护理</option>
                        <option value="24小时监护">24小时监护</option>

                    </select></td>
                </tr>
                <tr>
                    <td>营业时间</td>
                    <td><input type="date" v-model="querinfo.createTime"></td>
                </tr>
                <tr>
                    <td>机构地址</td>
                    <td><input type="text" v-model="querinfo.organAddr"></td>
                </tr>
                <tr>
                    <td>联系电话</td>
                    <td><input type="text" v-model="querinfo.tel"></td>
                </tr>
                <tr>
                    <td>发布时间</td>
                    <td><input type="radio" name="time" :value="1" v-model="querinfo.fbTime">立即发布
                        <input type="radio" name="time" :value="0" v-model="querinfo.fbTime">定时发布
                    </td>
                </tr>
                <tr>
                    <td>机构详情</td>
                    <td><textarea v-model="querinfo.xq"></textarea></td>
                </tr>
                
                <tr>
                    <td>分享</td>
                    <td><input type="number" v-model="querinfo.fxnum"></td>
                </tr>
                <tr>
                    <td>收藏</td>
                    <td><input type="number" v-model="querinfo.scnum"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" name="state" :value="1" v-model="querinfo.state">已发布
                        <input type="radio" name="state" :value="0" v-model="querinfo.state">未发布
                    </td>
                </tr>
                <tr>
                    <td>更新人</td>
                    <td><input type="text" v-model="querinfo.updPeople"></td>
                </tr>
                <tr>
                    <td>最后更新时间</td>
                    <td><input type="date" v-model="querinfo.endTime"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from '@/stores/user'
const a = useStore();
const route = useRoute();
const router = useRouter();

let querinfo: any = reactive({

  "organName": "",
  "sever": "",
  "fxnum": "",
  "scnum": "",
  "state": "",
  "updPeople": "",
  "endTime": "",
  "photo": "",
  "createTime": "",
  "organAddr": "",
  "tel": "",
  "fbTime": "",
  "xq": "",

})
const imgs=(e:any)=>{
    var obj=e.target.files[0];
    let f= new FormData();
    f.append("file",obj)
    axios({
        url:'/api/Img/Imgs',
        method:'post',
        data:f
    })
    .then(res=>{
        querinfo.photo=res.data
    })
}

const ok = () => {
    if (querinfo.organName == "") {
        alert("机构名称不能为空");
        return;
    }
    if (querinfo.photo == "") {
        alert("图片不能为空");
        return;
    }
    if (querinfo.sever == "") {
        alert("特色服务不能为空");
        return;
    }
    if (querinfo.organAddr == "") {
        alert("机构地址不能为空");
        return;
    }
    if (querinfo.tel == "") {
        alert("联系电话不能为空");
        return;
    }
    
    axios({
        url: '/api/Organ/OrganAdd',
        method: 'post',
        data: querinfo
    })
        .then(res => {
            console.log(res);
            
            if (res.data >=0) {
                alert("添加成功");
                router.push("/organlist")
                return;
            } else {
                alert("添加失败");
                
               
                return;
            }
        })
        .catch(err=>{
        console.log(err)
    })
}



</script>

<style scoped></style>